#ifndef ACAPELLA_SYNCHRONIZE_RW_LCOK_LINUX_H
#define ACAPELLA_SYNCHRONIZE_RW_LCOK_LINUX_H

#include <pthread.h>

namespace acapella
{
namespace synchronize
{

class rw_lock
{
public:
	rw_lock()
	{
		pthread_rwlock_init(&v_, NULL);
	}

	~rw_lock()
	{
		pthread_rwlock_destroy(&v_);
	}

	int read_lock()
	{
		return pthread_rwlock_rdlock(&v_);
	}

	int write_lock()
	{	
		return pthread_rwlock_wrlock(&v_);
	}

	int read_unlock()
	{
		return pthread_rwlock_unlock(&v_);
	}

	int write_unlock()
	{
		return pthread_rwlock_unlock(&v_);
	}

private:
	pthread_rwlock_t v_;

	rw_lock(const rw_lock&);
	rw_lock& operator=(const rw_lock&);
};

}
}

#endif
